package com.wsc.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wsc.goods.domain.Product;

import com.wsc.goods.domain.ProductExt;
import com.wsc.goods.mapper.ProductExtMapper;
import com.wsc.goods.mapper.ProductMapper;

import com.wsc.goods.service.ProductExtService;
import com.wsc.goods.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wsc
 * @since 2019-11-20
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Autowired
    private ProductExtMapper productExtMapper;

    @Autowired
    private ProductExtService productExtService;

    @Transactional
    public void saveProduct(Product product) {
        baseMapper.insert(product);
        productExtMapper.insert(product.getProductExt());
    }

    @Transactional
    public void updateProduct(Product product) {
        baseMapper.updateById(product);
        productExtService.update(new UpdateWrapper<ProductExt>()
                 .set("description",product.getProductExt().getDescription())
                .eq("product_id",product.getId()));

        this.update();
    }
}
